<template>
  <div>
    <el-table
      v-show="tableLazy"
      :data="tableData1"
      style="width: 100%"
      row-key="floc"
      border
      lazy
      :load="loadchildnode"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      size="mini"
      ref="table"
    >
      <el-table-column prop="equiDesc" label="设备描述"> </el-table-column>
      <el-table-column prop="floc" label="kks" align="center">
      </el-table-column>
      <el-table-column prop="appFloc" width="120px" label="状态" align="center">
        <template #default="{ row }">
          <span v-if="row.appFloc" style="color: #a4da89">已映射</span>
          <span v-else>未映射</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="{ row }">
          <span v-if="row.floc != '2521'">
            <el-button type="primary" size="mini" @click="handleAdd(row)"
              >新增</el-button
            >
            <el-button type="success" size="mini" @click="handleUpdate(row)"
              >编辑</el-button
            >
          </span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData1: []
    }
  },
  methods: {
    // 懒加载树
    loadNode (node, resolve) {
      // 如果展开第一级节点，从后台加载一级节点列表
      if (node.level === 0) {
        this.treeLoading = true
        this.loadfirstnodeTree(resolve)
      }
      // 如果展开其他级节点，动态从后台加载下一级节点列表
      if (node.level >= 1) {
        this.loadchildnodeTree(node, resolve)
      }
    },
    // 树加载第一级节点
    async loadfirstnodeTree (resolve) {
      const params = {
        floc: this.refreshData.floc
      }
      const res = await DeviceManage.getTreeDialog(this, params, null, {
        showMask: false
      })
      // 将设备的kks拼接到名字后面
      res.data.forEach((item) => {
        item.floc !== '' && (item.equiDesc = `${item.equiDesc}(${item.floc})`)
      })
      this.treeLoading = false
      return resolve(res.data)
    },
    // 树加载节点的子节点集合
    async loadchildnodeTree (node, resolve) {
      const params = {
        floc: node.data.floc
      }
      const res = await DeviceManage.getTreeDialog(this, params, null, {
        showMask: false
      })
      res.data.forEach((item) => {
        item.equiDesc = `${item.equiDesc}(${item.floc})`
      })
      return resolve(res.data)
    }
  }
}
</script>

<style>
</style>
